<!--
 * @Author: yaojian66 1327629137@qq.com
 * @Date: 2022-07-05 14:16:41
 * @LastEditors: yaojian66 1327629137@qq.com
 * @LastEditTime: 2022-07-05 17:35:31
 * @FilePath: \geyao\第一百零七题 购物面板.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>购物面板</title>
</head>

<body>
  <table>
    <thead>
      <caption>
        商品
      </caption>
    </thead>
    <tbody>
      <tr>
        <td>炸鸡</td>
        <td>28元</td>
        <td><button id="zjtaiduola">-</button></td>
        <td><span id="zjsl">0</span></td>
        <td><button id="zjtaishaola">+</button></td>
      </tr>
      <tr>
        <td>可乐</td>
        <td>5元</td>
        <td><button id="kltaiduola">-</button></td>
        <td><span id="klsl">0</span></td>
        <td><button id="kltaishaola">+</button></td>
      </tr>
      <tr>
        <td>总价：</td>
        <td><span id="total">0</span></td>
      </tr>
    </tbody>
  </table>
  <script>
    let total_zjsl = 0
    let total_klsl = 0
    let dom_zjtaiduola = document.querySelector('#zjtaiduola')
    let dom_zjsl = document.querySelector('#zjsl')
    let dom_zjtaishaola = document.querySelector('#zjtaishaola')
    let dom_kltaiduola = document.querySelector('#kltaiduola')
    let dom_klsl = document.querySelector('#klsl')
    let dom_kltaishaola = document.querySelector('#kltaishaola')
    let dom_total = document.querySelector('#total')

    function redraw() {
      dom_zjsl.innerText = total_zjsl
      dom_klsl.innerText = total_klsl
      dom_total.innerText = total_zjsl * 28 + total_klsl * 5
    }

    dom_zjtaiduola.onclick = function () {
      if (total_zjsl > 0) total_zjsl--
      redraw()
    }
    dom_zjtaishaola.onclick = function () {
      total_zjsl++
      redraw()
    }

    dom_kltaiduola.onclick = function () {
      if (total_klsl > 0) total_klsl--
      redraw()
    }
    dom_kltaishaola.onclick = function () {
      total_klsl++
      redraw()
    }
  </script>
</body>

</html>